<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Swagger UI</title>
  <link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32"/>
  <link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16"/>
  <link href='webjars/springfox-swagger-ui/css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='webjars/springfox-swagger-ui/css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='webjars/springfox-swagger-ui/css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
  <link href='webjars/springfox-swagger-ui/css/reset.css' media='print' rel='stylesheet' type='text/css'/>
  <link href='webjars/springfox-swagger-ui/css/print.css' media='print' rel='stylesheet' type='text/css'/>
  <script src='webjars/springfox-swagger-ui/lib/jquery-1.8.0.min.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/jquery.slideto.min.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/jquery.wiggle.min.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/handlebars-2.0.0.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/underscore-min.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/backbone-min.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/swagger-ui.min.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/highlight.7.3.pack.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/marked.js' type='text/javascript'></script>
  <script src='webjars/springfox-swagger-ui/lib/swagger-oauth.js' type='text/javascript'></script>

  <script src='webjars/springfox-swagger-ui/springfox.js' type='text/javascript'></script>
  <script type="text/javascript">
    $(function() {

      window.springfox.uiConfig(function(data) {
        window.swaggerUi = new SwaggerUi({
          dom_id: "swagger-ui-container",
          validatorUrl: data.validatorUrl,
          supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
          onComplete: function(swaggerApi, swaggerUi) {

            initializeSpringfox();

            if (window.SwaggerTranslator) {
              window.SwaggerTranslator.translate();
            }

            $('pre code').each(function(i, e) {
              hljs.highlightBlock(e)
            });

            // !!! Added this function call to match custom CSRF header
            addApiKeyAuthorization();
          },
          onFailure: function(data) {
            log("Unable to Load SwaggerUI");
          },
          docExpansion: "none",
          apisSorter: "alpha",
          showRequestHeaders: false
        });

        // !!! Changed this function to match custom CSRF header
        function addApiKeyAuthorization() {
          var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("X-CSRF-TOKEN", getCSRF(), "header");
          window.swaggerUi.api.clientAuthorizations.add("key", apiKeyAuth);
        }

        // !!! Added this function to match custom CSRF header
        function getCSRF() {
          var name = "CSRF-TOKEN=";
          var ca = document.cookie.split(';');
          for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1);
            if (c.indexOf(name) !== -1) {
                return c.substring(name.length, c.length);
            }
          }
          return "";
        }

        $('#input_apiKey').change(addApiKeyAuthorization);

        function log() {
          if ('console' in window) {
            console.log.apply(console, arguments);
          }
        }

        function oAuthIsDefined(security) {
          return security.clientId
              && security.clientSecret
              && security.appName
              && security.realm;
        }

        function initializeSpringfox() {
          var security = {};
          window.springfox.securityConfig(function(data) {
            security = data;
            window.apiKeyVehicle = security.apiKeyVehicle || 'query';
            if (security.apiKey) {
              $('#input_apiKey').val(security.apiKey);
              addApiKeyAuthorization();
            }
            if (typeof initOAuth == "function" && oAuthIsDefined(security)) {
              initOAuth(security);
            }
          });
        }
      });
    });
  </script>
</head>

<body class="swagger-section">
<div id='header'>
  <div class="swagger-ui-wrap">
    <a id="logo" href="http://swagger.io">swagger</a>

    <form id='api_selector'>
      <div class='input'>
        <select id="select_baseUrl" name="select_baseUrl"/>
      </div>
      <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/>
      </div>
      <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
      <div class='input'><a id="explore" href="#" data-sw-translate>Explore</a></div>
    </form>
  </div>
</div>

<div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</body>
</html>
